package com.warehouse.utils;

import java.util.Calendar;
import java.util.UUID;

/**
 * uuid(时间戳版)
 */
public class RandomUUID {
    private static Calendar cal = Calendar.getInstance();//当前日期

    public static String generatorUUID(){
         return NowTime() + UUID.randomUUID().toString().replace("-","").substring(0,6);
    }
    //当前时间
    public static String NowTime(){
        StringBuilder stringBuilder = new StringBuilder();
        //生成年月日时分秒
        stringBuilder.append(cal.get(Calendar.YEAR));
        stringBuilder.append(cal.get(Calendar.MONTH)+1);
        stringBuilder.append(cal.get(Calendar.DATE));
        stringBuilder.append(cal.get(Calendar.HOUR_OF_DAY));
        stringBuilder.append(cal.get(Calendar.MINUTE));
        stringBuilder.append(cal.get(Calendar.SECOND));
        return stringBuilder.toString();
    }

    //当前时间（加-）
    public static String NowTimeByS(){
        StringBuilder stringBuilder = new StringBuilder();
        //生成年月日时分秒
        stringBuilder.append(cal.get(Calendar.YEAR)+"-");
        Integer month = cal.get(Calendar.MONTH)+1;
        if (month<10){
            stringBuilder.append("0"+month+"-");
        }
        if (month>9){
            stringBuilder.append(month+"-");
        }

        if (cal.get(Calendar.DATE)<10){
            stringBuilder.append("0"+cal.get(Calendar.DATE)+" ");
        }
        if (cal.get(Calendar.DATE)>9){
            stringBuilder.append(cal.get(Calendar.DATE)+" ");
        }

        if (cal.get(Calendar.HOUR_OF_DAY)<10){
            stringBuilder.append("0"+cal.get(Calendar.HOUR_OF_DAY)+"-");
        }
        if (cal.get(Calendar.HOUR_OF_DAY)>9){
            stringBuilder.append(cal.get(Calendar.HOUR_OF_DAY)+"-");
        }
        stringBuilder.append(cal.get(Calendar.MINUTE));
        return stringBuilder.toString();
    }
}
